<template>
  <ContentWrap>
    <el-form :model="queryParams" label-width="80px" :inline="true">
      <!-- 套餐类型、会员、手机号码、核销时间、所属门店 -->
      <el-form-item label="套餐">
        <el-select v-model="queryParams.packageId" class="!w-240px" placeholder="请选择套餐名称">
          <el-option
            v-for="item in packageList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="会员">
        <el-input v-model="queryParams.member" class="!w-240px" placeholder="请输入会员" />
      </el-form-item>
      <el-form-item label="手机号码">
        <el-input v-model="queryParams.phone" class="!w-240px" placeholder="请输入手机号码" />
      </el-form-item>
      <el-form-item label="核销时间">
        <el-date-picker
          v-model="queryParams.verificationTime"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="所属门店">
        <el-select v-model="queryParams.store" class="!w-240px" placeholder="请选择所属门店">
          <el-option v-for="item in storeList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </el-form-item>
      <!-- 搜索 -->
      <div class="flex justify-end align-center">
        <el-button type="primary" @click="handleQuery">搜索</el-button>
        <el-button @click="handleReset">重置</el-button>
      </div>
    </el-form>
  </ContentWrap>
  <ContentWrap>
    <el-table v-loading="loading" :data="tableData" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="核销时间" prop="verificationTime" align="center">
        <template #default="scope">
          <span>{{ formatDate(scope.row.verificationTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属门店" prop="storeId" align="center">
        <template #default="scope">
          <span>{{ storeList.find((item: any) => item.id === scope.row.storeId)?.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员信息" align="center">
        <template #default="scope">
          <div>
            <div>会员名称：{{ scope.row.name || '--' }}</div>
            <div> 手机号： {{ scope.row.phone || '--' }}</div>
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column label="套餐类型" prop="packageId" align="center" /> -->
      <el-table-column label="套餐名称" prop="packageName" align="center" />
    </el-table>
    <Pagination
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      :total="total"
      @pagination="getUsageRecordPage"
    />
  </ContentWrap>
</template>
<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { SofaBasicApi } from '@/api/application/sofa'
import * as DeliveryPickUpStoreApi from '@/api/mall/trade/delivery/pickUpStore/index'
import { formatDate } from '@/utils/formatTime'
const queryParams = ref({
  packageId: undefined,
  member: '',
  phone: '',
  verificationTime: [],
  store: undefined,
  pageNo: 1,
  pageSize: 10
})
const total = ref<number>(0)
const packageList = ref<any>([])
const tableData = ref<any>([])
const loading = ref(false)
const storeList = ref<any>([])
const handleQuery = () => {
  getUsageRecordPage()
}
const handleReset = () => {
  queryParams.value = {
    packageId: undefined,
    member: '',
    phone: '',
    verificationTime: [],
    store: undefined,
    pageNo: 1,
    pageSize: 10
  }
  getUsageRecordPage()
}
const getUsageRecordPage = () => {
  SofaBasicApi.getPackageOrderPage(queryParams.value).then((res) => {
    tableData.value = res.list
    total.value = res.total
  })
}
const getStoreList = async () => {
  const res = await DeliveryPickUpStoreApi.getDeliveryPickUpStorePage({
    pageNo: 1,
    pageSize: 100
  })
  storeList.value = res.list
}
// 获取套餐列表
const getPackageList = async () => {
  const res = await SofaBasicApi.getPackageList({
    pageNo: 1,
    pageSize: 100
  })
  packageList.value = res
}
onMounted(() => {
  getUsageRecordPage()
  getStoreList()
  getPackageList()
})
</script>
<style lang="scss" scoped></style>
